package testrj.sample.web;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import testrj.domain.MethodToTest;
import testrj.domain.TestrjConfig;
import testrj.rjson.RjsonConfig;

/**
 * Servlet implementation class HelloWorldServlet
 */
public class HelloWorldServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public HelloWorldServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		RjsonConfig.registerTransformer(new HttpServletRequestTransformer(), true);
		RjsonConfig.registerTransformer(new HttpServletResponseTransformer(), true);
		RjsonConfig.registerTransformer(new HttpSessionTransformer(), true);
		
		HttpSession session = request.getSession();
		session.setAttribute("SOMEKEY", "SOMEVALUE");
		session.setAttribute("PERSONKEY", new Person());
		
		TestrjConfig.testsFolderLocation = "/Users/daveayan/development/testdata/";
		MethodToTest m = new MethodToTest();
		m.record(this.getClass().getName(), "doGet", new Object[] {request, request.getSession()});
		System.out.println("In doGet");
		m.recordReturnValueAndPersist(response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("In doPost");
	}

}
